package com.hs.controller;

import com.hs.util.R;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * @ClassName FileController
 * @Description TODO
 * @Author qiuye
 * @Date 2025年07月31日 19:25
 * @Version 1.0
 */
@RestController
public class FileController {
    @Value("E:/static/")
    private String filePath;

//    上传请求
    @PostMapping("upload")
    public R uploadFile(MultipartFile file) throws IOException {
        if (file.isEmpty()) {
            return R.fail();
        }
        String fileName = file.getOriginalFilename();
       fileName = UUID.randomUUID().toString()+fileName;

       file.transferTo(new File(filePath + fileName));
       return R.ok(fileName);
    }
}
